package hb.software.service.role.impl;

import hb.software.role.dao.RoleDao;
import hb.software.role.entity.Role;
import hb.software.service.role.RoleManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import edu.zut.hb.software.base.service.impl.GenericStudentManagerImpl;

import java.util.List;

public class RoleManagerImpl extends GenericStudentManagerImpl<Role, Long> implements RoleManager {

	RoleDao roleDao;

	@Autowired
	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
		this.dao = this.roleDao;
	}

	@Override
	public List<Role> findByname(String string) {
		// 创建查询条件数据对象
		Role queryObject = new Role();
		queryObject.setUsername(string);
		ExampleMatcher matcher = ExampleMatcher.matching() // 构建对象
				.withMatcher("name", GenericPropertyMatchers.startsWith()) // 姓名采用“开始匹配”的方式查询
				.withIgnorePaths("dateCreated", "dateModified");
		// 创建实例并查询
		Example<Role> ex = Example.of(queryObject, matcher);
		List<Role> result = dao.findAll(ex);
		return result;

	}

}
